/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.ui.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.helper.ModelerHelper;

/**
 * 
 * 
 * @author Patrick Tessier
 * 30 juin 06
 * @deprecated
 */
@Deprecated
public class CreateElementDialog extends Dialog{
	
	/**
	 * 
	 */
	private Combo combo;
	
	/**
	 * 
	 */
	private String[] elementList= {	"Diagram",
   												"Package"};
	
	/**
	 * 
	 */
	private Text nameField;
	
	/**
	 * 
	 */
	private Element umlElement;
	
	/**
	 * 
	 * 
	 * @param parentShell 
	 * @param umlElement 
	 */
	public CreateElementDialog(Shell parentShell, Element umlElement){
		super(parentShell);
		this.umlElement=umlElement;
	}
	
	/**
	 * 
	 * 
	 * @param parent 
	 * 
	 * @return 
	 */
	@Override
	protected Control createDialogArea(Composite parent){
		Composite comp=(Composite)super.createDialogArea(parent);
		
		GridLayout layout=(GridLayout)comp.getLayout();
		layout.numColumns=2;
		Label elementToCreate =new Label(comp, SWT.RIGHT|SWT.SINGLE);
		elementToCreate.setText("Element to create: ");
		
		combo = new Combo (comp, SWT.READ_ONLY);
		combo.setItems (elementList);
		combo.setSize (400, 400);
		Label nameLabel=new Label(comp, SWT.RIGHT);
		nameLabel.setText("Element name: ");
		nameField =new Text(comp, SWT.SINGLE);
		nameField.setSize(300, 20);
		GridData data= new GridData(GridData.FILL_HORIZONTAL);
		nameField.setLayoutData(data);
		data.widthHint=250;
		
		return comp;
	}
	
	/**
	 * 
	 * 
	 * @param parent 
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent){
		super.createButtonsForButtonBar(parent);
		
	}
	
	/**
	 * 
	 * 
	 * @param buttonId 
	 */
	@Override
	protected void buttonPressed(int buttonId){
		super.buttonPressed(buttonId);
	}
	
	/**
	 * 
	 */
	@Override
	protected void okPressed(){
		switch(combo.getSelectionIndex()){
			case 0:
				//diagram
				//if (nameField.getText().trim()!=""){
				//ModelerFactory.getInstance().createDiagramAtModel(nameField.getText().trim(), umlElement);}
				break;
			case 1:
				//package
				if ((nameField.getText().trim()!="")
					&&(	umlElement instanceof Package)){
					ModelerHelper.getFactory().createUMLElement(org.eclipse.uml2.uml.Package.class, nameField.getText().trim(), umlElement);}
			default:
				break;
				
		}
		
		super.okPressed();
	}

}
